package design.patterns.creation;

/**
 * 抽象工厂模式
 * 解释：
 * 抽象工厂模式是一种创建型设计模式，
 * 它能创建一系列相关的对象， 而无需指定其具体类。
 */

/**
 * 情景
 * 过家家的房子需要装修
 * 要求：保持椅子、沙发装修风格统一
 */
public class B_AbstractFactory {
    public static void main(String[] args) {
        String style1 = "1";
        String style2 = "2";

        String customerStyle = "2";
        if (customerStyle.equals(style1)){
            Style1Factory style1Factory = new Style1Factory();
            style1Factory.createChair().paintStyle();
            style1Factory.createSofa().paintStyle();
        }else if (customerStyle.equals(style2)){
            Style2Factory style2Factory = new Style2Factory();
            style2Factory.createChair().paintStyle();
            style2Factory.createSofa().paintStyle();
        }
    }
}

interface Chair{
    void paintStyle();
}
interface Sofa{
    void paintStyle();
}

interface StyleFactory{
    Chair createChair();
    Sofa createSofa();
}
class Style1_Chair implements Chair{
    private String style;

    @Override
    public void paintStyle() {
        System.out.println("style1 chair");
    }
}
class Style1_Sofa implements Sofa{

    @Override
    public void paintStyle() {
        System.out.println("style1 sofa");
    }
}
class Style2_Chair implements Chair{
    private String style;

    @Override
    public void paintStyle() {
        System.out.println("style2 chair");
    }
}
class Style2_Sofa implements Sofa{

    @Override
    public void paintStyle() {
        System.out.println("style2 sofa");
    }
}
class Style1Factory implements StyleFactory {

    @Override
    public Chair createChair() {
        return new Style1_Chair();
    }

    @Override
    public Sofa createSofa() {
        return new Style1_Sofa();
    }
}

class Style2Factory implements StyleFactory {

    @Override
    public Chair createChair() {
        return new Style2_Chair();
    }

    @Override
    public Sofa createSofa() {
        return new Style2_Sofa();
    }
}